package com.hand.yd24378.spring_practice;

import org.aspectj.lang.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class HelloAspect {

	/**
	 * 获取日志对象
	 */
	private final static Logger logger = LoggerFactory.getLogger(HelloAspect.class);

	/**
	 * 拦截
	 */
	@Pointcut("execution(public * com.hand.yd24378.spring_practice.Person.*(..))")
	public void log() {
	}

	@Before("log()")
	public void doBefore() {
		logger.info("================log start====================");
		// before 工号
		logger.info("before 24378 李伟丰");
		logger.info("================log end====================");
	}

	@After("log()")
	public void doAfter() {
	}

	@AfterReturning(returning = "object", pointcut = "log()")
	public void doAfterReturning(Object object) {
		logger.info("response={}", object.toString());
		logger.info("================log start====================");
		// after 工号
		logger.info("after 24378 李伟丰");
		logger.info("================log end====================");
	}
}

